using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GameLib
{
    class Layer
    {
        public Color[] Pixels
        {
            get { return pixels; }
        }
        Color[] pixels;

        public Texture2D Canvas
        {
            get { return canvas; }
        }
        Texture2D canvas;

        public Layer(GraphicsDevice device)
        {
            Rectangle viewportBounds = device.Viewport.Bounds;
            canvas = new Texture2D(device, viewportBounds.Width, viewportBounds.Height);
            pixels = new Color[canvas.Width * canvas.Height];
            for (int i = 0; i < pixels.Length; i++)
            {
                pixels[i] = Color.Transparent;
            }
            canvas.SetData<Color>(pixels);
        }

        public Layer(GraphicsDevice device, Color[] data)
        {
            Rectangle viewportBounds = device.Viewport.Bounds;
            canvas = new Texture2D(device, viewportBounds.Width, viewportBounds.Height);
            pixels = new Color[canvas.Width * canvas.Height];
            for (int i = 0; i < pixels.Length; i++)
            {
                pixels[i] = data[i];
            }
            canvas.SetData<Color>(pixels);
        }

        public void SetPixels(Color[] newData)
        {
            for (int i = 0; i < pixels.Length; i++)
            {
                pixels[i] = newData[i];
            }
            canvas.SetData<Color>(pixels);
        }

        public void SetData()
        {
            canvas.SetData<Color>(pixels);
        }

        public void Draw(SpriteBatch sp)
        {
            sp.Draw(canvas, Vector2.Zero, Color.White);
        }
    }
}
